<template>
  <van-nav-bar title="京东登录" left-text="返回" left-arrow @click-left="$router.go(-1)" />
  <van-form @submit="onSubmit">
    <van-cell-group inset>
      <van-field v-model="username" name="loginname" label="用户名" placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]" />
      <van-field v-model="password" type="password" name="password" label="密码" placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]" />
    </van-cell-group>
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit">
        提交
      </van-button>
    </div>
  </van-form>
  <h1>去注册</h1>
  <div class="zc" @click="zzc">
    <p>快速注册</p>
    <van-icon name="arrow" />
  </div>
</template>

<script  setup lang="ts">
import { ref } from 'vue';
import { loginapi } from '@/api/loginapi'
import router from '@/router/index';
import { Dialog } from 'vant';
import { useUserStore } from '@/store/userstore';
const useStore = useUserStore();
// import { useRouter } from 'vue-router';
const username = ref('')
const password = ref('')
const onSubmit = (values: object) => {
  loginapi(values).then((res: any) => {
    console.log(res);
    if (res.code == '10010') {
      Dialog.alert({
        title: '提示',
        message: '用户未注册,请先注册!',
      }).then(() => {
        router.push('/register/zhuce')
      })
    } else if (res.code == '200') {
      router.push('/home')
      // useStore.setUserId(res.data?.userid)
      localStorage.setItem('token', res.data.token)
      localStorage.setItem('userid', res.data.userid)
    }
  })
}

const zzc = () => {
  router.push('/register/zhuce')
}


</script>
<style lang="scss" scoped>
h1 {
  color: aquamarine;
  font-size: 16px;
  margin-left: 20px;
}

.zc {
  width: 90%;
  margin: 0 auto;
  background-color: #ccc;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>